//index.js
//获取应用实例
var app = getApp();
//console.log(app.globalData);
Page({
  data: {
    userInfo: {},
    region: [],
    customItem: '全部',
    status: 0,
    location: '',
    address: '',
    id: 0,
    paytypeText:'',
    paytype:'',
    store_id: 0,
    data: {},
    release_day: '',
    deadline: '',
    paytypeArray:[
      'alipay',
      'wxpay',
      'cash',
      'other',
    ],
    paytypes: [
       '支付宝',
       '微信',
       '现金',
       '其它',
    ]
  },
  bindPickerChange: function (e) {
    var v = Number(e.detail.value);
    var paytypeText = this.data.paytypes[v];
    this.data.paytype = this.data.paytypeArray[v];
    console.log(this.data.paytype);
    this.setData({ paytypeText: paytypeText });
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.id ) {
      this.data.id = options.id;
      this.init();
    }
    
  },
 
  init: function () {
    var that = this;
    app.api("api/community_bills/find", {
      bill_entry_id: this.data.id  ,
    }, function (res) {
      that.data.loading = 0;
      if (res.code != 200) {
        app.alert(res.msg);
        return;
      }
      that.setData({
        data: res.data,
        deadline: res.data.deadline,
        release_day: res.data.release_day,
      });
    })
  },

  formSubmit: function (e) {
    console.log(this.data);
    var postData = e.detail.value;
    if (!this.data.paytype) {
      app.alert("请选择收款方式");
      return false;
    }
    
    
    var that = this;
    that.setData({ 'loading': 1 });
    that.setData({ 'disabled': 1 });
    app.api("api/community_bills/billStatus", {
      method: 'POST',
      bill_entry_id: this.data.id,
      paytype: this.data.paytype,
      remark: postData.remark,
    }, function (res) {
      if (res.code != 200) {
        app.alert(res.msg);
        that.data.payloading = 0;
        that.setData({ 'loading': 0 });
        that.setData({ 'disabled': 0 });
        return false;
      }
      // that.reset();
      wx.showToast({
        title: '收款成功',
        icon: 'success',
        duration: 2000
      })
      app.setPageData("tenement/bills", { reload: 1 });
      wx.navigateTo({
        url: '/pages/tenement/bills',
      })
    })

  }


})
